package org.mijia.dotsbox.core.model;

import java.util.Date;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.mijia.dotsbox.core.EntityField;

public class Channel implements Entity {
	
	private String id;
	private String parentId;
	private String title;
	private String description;
	private String author;
	private String homepage;
	private Date lastModified;
	private String imageUrl;
	private String feedFormat;
	
	public Channel() {
		id = parentId = "";
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@EntityField (name = "parentId", index = EntityField.INDEX_UNTOKENIZE)
	public String getParentId() {
		return parentId;
	}
	
	public void setParentId(String parentId) {
		this.parentId = parentId;
	}
	
	@EntityField (name = "title")
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
		if (id == null || id.equals(""))
			setId(title);
	}
	
	@EntityField (name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@EntityField (name = "author")
	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	@EntityField (name = "homepage", index = EntityField.INDEX_NO)
	public String getHomepage() {
		return homepage;
	}

	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}

	@EntityField (name = "lastModified", index = EntityField.INDEX_NO, valueType = "java.util.Date")
	public Date getLastModified() {
		return lastModified;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}

	@EntityField (name = "imageUrl", index = EntityField.INDEX_NO)
	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	@EntityField (name = "feedFormat", index = EntityField.INDEX_NO)
	public String getFeedFormat() {
		return feedFormat;
	}

	public void setFeedFormat(String feedFormat) {
		this.feedFormat = feedFormat;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		
		if (obj instanceof String) {
			String link = (String) obj;
			return link.equals(id);
		}
		
		if (obj instanceof Channel) {
			Channel other = (Channel) obj;
			return id.equals(other.id);
		}
		
		return false;
	}

	@Override
	public int hashCode() {
		return id.hashCode();
	}
	
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}

}
